/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package AA;

/**
 *
 * @author asc
 */
public class P102
{
    
    int[][] prod;
    Boolean[] Visitados;
    int[] minimo;
    int Sol;
    int tamanyo;
    int nSuper;
    
    public int best(String[] data){
        Sol = Integer.MAX_VALUE;
        nSuper = data.length;
        
        for (int i = 0; i < nSuper; i++)
        {
            String[] products = data[i].split("\\p{Space}+");
            
            if(i==0){
                tamanyo = products.length;
                prod = new int [nSuper][tamanyo];
                Visitados = new Boolean[nSuper];
                minimo = new int[tamanyo];
                //minimo[0] = 0;
            }
            Visitados[i]=false;
            for (int j = tamanyo-1; j >= 0; j--)
            {
                prod[i][j] = Integer.decode(products[j]);
                
                if(i==0)minimo[j] = prod[i][j];
                else minimo[j] = Math.min(prod[i][j], minimo[j]);
                
                if(i==nSuper-1 && j!=tamanyo-1)minimo[j]+=minimo[j+1];
            }
        }
        
        cestaCompra(0, 1);
        prod=null;
        return Sol;
    }
    
    
    void cestaCompra(int value, int posicion){
        
        if(posicion>=tamanyo){
            if(Sol >= value){
                Sol = value;
            }
        }
        else if(value + minimo[posicion] < Sol){    
            for (int i = 0; i < nSuper; i++)
            {
                if(Visitados[i]){
                    cestaCompra(value + prod[i][posicion] , posicion+1);
                }
                else{
                    Visitados[i]=true;
                    cestaCompra(value + prod[i][posicion] + prod[i][0], posicion+1);
                    Visitados[i]=false;
                }
                    
            }
        }
    }
    
    public static void main(String[] args)
    {
        P102 p = new P102();
        System.out.print(p.best(args) + "\n");
    }
    
}
